public class Solution6 {
    //122. 买卖股票的最佳时机 II
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int[] f = new int[n]; //买入
        int[] g = new int[n]; //卖出
        f[0] = -prices[0];
        for (int i = 1; i < n; i++) {
            f[i] = Math.max(f[i-1],g[i-1] - prices[i]);
            g[i] = Math.max(g[i-1],f[i-1] + prices[i]);
        }
        return g[n-1];

    }
}
